#include <iostream> 
#include <stack>
using namespace std;
const int Maxn = 1e5 + 7;
int n;
char In[Maxn];
char Out[Maxn];
int main()
{
    cin >> n;
    scanf("%s", In);
    scanf("%s", Out);
    stack<char> s;
    int ans = 0;
    int i = 0; //遍历Out
    int j = 0; //遍历In while(i<n)
    while (i<n)
    {
        if (s.empty() || s.top() != Out[i]) //栈为空或者栈顶不是当前out
        {
            s.push(In[j]);
            j++;
            if (s.size() > ans)
                ans = s.size();
        }
        else
        {
            s.pop();
            i++;
        }
    }
    cout << ans << endl;
    system("pause");
    return 0;
}